package com.jsg.sl651.util;

import io.netty.buffer.ByteBuf;

import java.util.Locale;

/**
 * CRC 校验码计算
 */
public final class CRC {
    private static final int CRC = 0x0000ffff;
    private static final int POLYNOMIAL = 0x0000a001;
    public static int crc16(byte[] bytes) {
        int crc = CRC;
        int i, j;
        for (i = 0; i < bytes.length; i++) {
            crc ^= ((int) bytes[i] & 0x000000ff);
            for (j = 0; j < 8; j++) {
                if ((crc & 0x00000001) != 0) {
                    crc >>= 1;
                    crc ^= POLYNOMIAL;
                } else {
                    crc >>= 1;
                }
            }
        }
        return crc;
    }




}
